package algotithm.interview.Boss直聘.test2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/31-20:04
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        String[] queries = {"FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"};
        String pattern = "FoBa";
        boolean[] booleans = solution.camelMatch(queries, pattern);
        for (int i = 0; i < booleans.length; i++) {
            System.out.print(booleans[i] + " ");
        }
    }

    public boolean[] camelMatch (String[] queries, String pattern) {
        List<Boolean> ans = new ArrayList<>();
        for (String str : queries) {
            ans.add(isMatch(str,pattern));
        }
        int n = ans.size();
        boolean[] res = new boolean[n];
        for (int i = 0; i < n; i++) {
            res[i] = ans.get(i);
        }
        return res;

    }

    public boolean isMatch(String query,String pattern) {
        int idx1 = 0, idx2 = 0, n1 = query.length(),n2 = pattern.length();
        while (idx1 < n1 && idx2 < n2) {
            char c1 = query.charAt(idx1);
            char c2 = pattern.charAt(idx2);
            if (c1 == c2) {
                idx1++;
                idx2++;
            } else {
                if (c1 >= 'A' && c1 <= 'Z') {
                    return false;
                }
                idx1++;
            }
        }
        if (idx2 != n2) {
            return false;
        }
        while (idx1 < n1) {
            char c = query.charAt(idx1++);
            if (c >= 'A' && c <= 'Z') {
                return  false;
            }
        }
        return true;
    }

}
